package com.scy.controller;


import com.scy.pojo.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {


// 框架自动调用
    public TestController() {
        System.out.println("TestController的无参构造方法执行了---当前TestController对象的hashCode是:"+System.identityHashCode(this));
    }
    // 框架自动调用
    static {
        System.out.println("TestController的静态代码块执行了");
    }

    // 框架自动调用
    {
        System.out.println("TestController的构造代码块执行了---当前TestController对象的hashCode是:"+System.identityHashCode(this));
    }

    /**
     *  经验证 采用RequestMapping 注释,get和post请求均支持.
     * @param user
     * @return
     */
    @RequestMapping("/test1")
    @ResponseBody
    public User test1(@RequestBody User user) {
        System.out.println(user.getName() + "-------进入TestController类的test1方法了------" + user.getAddr());
        User user1 = new User("scy时春跃", "shanghai上海");
        return user1;
    }

}
